package com.office.supplies.controller;

import com.github.pagehelper.PageInfo;
import com.office.supplies.pojo.Goods;
import com.office.supplies.pojo.Notice;
import com.office.supplies.pojo.Result;
import com.office.supplies.pojo.dto.AddGoodsDTO;
import com.office.supplies.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Author admin
 * @Description 系统公告
 * @Date 2025/05/08/14:04
 */
@RestController
@RequestMapping("/notice")
@RequiredArgsConstructor
public class NoticeController {

    private final NoticeService noticeService;

    /**
     * 查询系统公告
     *
     * @param pageNum  Integer
     * @param pageSize Integer
     * @return Result<PageInfo < Goods>>
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public Result<PageInfo<Notice>> getNoticeList(@PathVariable("pageNum") Integer pageNum,
                                                  @PathVariable("pageSize") Integer pageSize) {
        return Result.success(noticeService.getNoticeList(pageNum, pageSize));
    }

    @PostMapping("/add")
    public Result<String> addNotice(@RequestBody Notice notice) {
        notice.setCreateTime(null);
        noticeService.save(notice);
        return Result.success("添加成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<String> deleteNotice(@PathVariable("id") Long id) {
        noticeService.removeById(id);
        return Result.success("删除成功");
    }

    @PutMapping("/update")
    public Result<String> updateNotice(@RequestBody Notice notice) {
        notice.setCreateTime(null);
        noticeService.updateById(notice);
        return Result.success("修改成功");
    }


}
